package com.example.run_game;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;
 
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
 
public class HistoryAdapter extends BaseAdapter {
 
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
 
    public HistoryAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
 
    public int getCount() {
        return data.size();
    }
 
    public Object getItem(int position) {
        return position;
    }
 
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.history_list_row, null);
 
        TextView routeID = (TextView)vi.findViewById(R.id.routeID); // date
        TextView date = (TextView)vi.findViewById(R.id.date); // date
        TextView distance = (TextView)vi.findViewById(R.id.distance); // distance
        TextView time = (TextView)vi.findViewById(R.id.time); // time
 
        HashMap<String, String> history = new HashMap<String, String>();
        history = data.get(position);
 
        // Setting all values in listview
        routeID.setText(history.get(RunHistory.KEY_ID));
        long seconds = Long.parseLong( history.get(RunHistory.KEY_START) );
        Date dateText = new Date(seconds);
        date.setText(dateText.toString());
        distance.setText("Distance: " + history.get(RunHistory.KEY_DISTANCE));
        time.setText("Time: " + history.get(RunHistory.KEY_TIME));
          	
        return vi;
    }
 
}